package com.fisicaapp;

import java.text.DecimalFormat;
import java.util.ArrayList;

import android.util.Log;

public class Trayectoria {
	private ArrayList<Double> posX;
    private ArrayList<Double> posY;
    private ArrayList<Double> velX;
    private ArrayList<Double> velY;
    private ArrayList<Double> tiempos;    
    private DecimalFormat dformat ; // variable para dejar formato de numeros en dos decimales    
    private float posInicialX, posInicialY, posFinalX, posFinalY,
    		posAnteriorX, posAnteriorY,timeInicial, timeFinal, timePivote,distRecorridaTotal; // Pivote para restar
    
    
    public Trayectoria(){
    	posX = new ArrayList<Double>();
    	posY = new ArrayList<Double>();
    	velX = new ArrayList<Double>();
    	velY = new ArrayList<Double>();
    	tiempos = new ArrayList<Double>();
    	distRecorridaTotal = 0;
    	posInicialX = 0;
    	posInicialY = 0;
    	posFinalX = 0;
    	posFinalY = 0;
    	posAnteriorX = 0;
    	posAnteriorY = 0;
    	timeInicial = 0;
    	timeFinal = 0;
    	timePivote = 0;
    	dformat = new DecimalFormat("0.00"); // defino que formato decimal sera de dos decimales (se trunca)
    }
    
    public void setPosInicialXY(float x, float y, float t){
    	posInicialX = x;
    	posInicialY = y;    	
    	timeInicial = t;
    	
    }
    public void setPosFinalXY(float x, float y, float tiempo){
    	posFinalX = x;
    	posFinalY = y;
    	timeFinal = tiempo;
    	
    }
    public void setPosAnteriorXY(float x, float y,float tiempo){
    	posAnteriorX = x;
    	posAnteriorY = y;
    	timeFinal = tiempo;
    }
    
    public void setTiempoPivote(float t){
    	timePivote = t;
    }
    
    public ArrayList<Double> getPosX(){ return posX; }
    public ArrayList<Double> getPosY(){ return posY; }
    public ArrayList<Double> getVelX(){ return velX; }
    public ArrayList<Double> getVelY(){ return velY; }
    public ArrayList<Double> getTiempos(){ return tiempos; }
    
    public float getTiempoFinal(){ return timeFinal; }
    public float getTiempoPivote(){ return timePivote; }
    public float getPosAnteriorX(){ return posAnteriorX; }
    public float getPosAnteriorY(){ return posAnteriorY; }
    public float getPosInicialX(){ return posInicialX; }
    public float getPosInicialY(){ return posInicialY; }
    public float getPosFinalX(){ return posFinalX; }
    public float getPosFinalY(){ return posFinalY; }
    public float getDistRecorridaTotal(){ return distRecorridaTotal; }
    public float getDesplazamientoX(){ return posFinalX - posInicialX;  }
    public float getDesplazamientoY(){ return -(posFinalY - posInicialY);  }
    
    public void addPosXY(double x,double y){
    	posX.add(new Double(x));
    	posY.add(new Double(y));
    }    
   
    public void addVelXY(double x,double y){
    	velX.add(new Double(x));
    	velY.add(new Double(y));
    }
    public void addTiempo(double t){
    	tiempos.add(new Double(t));
    }
    
    
    public void setTPivote(float t){
    	timePivote = t;
    }
    public void updateDistRecorridaTotal(double dx, double dy){
    	distRecorridaTotal += Math.sqrt(dx*dx + dy*dy);
    }
       
    
    public void cleanPos(){
    	posX.clear();
    	posY.clear();    	
    }
    public void cleanVel(){
    	velX.clear();
    	velY.clear();    
    }
    public void cleanTiempo(){
    	tiempos.clear();
    	timeInicial = 0;
    	timeFinal = 0;
    	timePivote = 0;
    }
    public void cleanAll(){
    	posX.clear();
    	posY.clear();
    	velX.clear();
    	velY.clear();
    	tiempos.clear();
    	distRecorridaTotal = 0;
    	distRecorridaTotal = 0;
    	posInicialX = 0;
    	posInicialY = 0;
    	posFinalX = 0;
    	posFinalY = 0;
    	posAnteriorX = 0;
    	posAnteriorY = 0;
    	timeInicial = 0;
    	timeFinal = 0;
    	timePivote = 0;
    }
    
    public double[] arrayListIntoArrayDouble(ArrayList<Double> ar){
    	double resp[] = new double[ar.size()];
    	String dato = "";
    	for (int i=0;i<ar.size();i++){
    		dato = dformat.format(ar.get(i).doubleValue());
    		dato = dato.replace(',','.');
    		resp[i] = Double.parseDouble(dato);
    	}
    	return resp;
    }
    
    
    public void imprimirAL(String tag,ArrayList<Double> ar){
    	String pr= "";
    	
    	for (int j=0;j<ar.size();j++){
    		pr += String.valueOf(ar.get(j).doubleValue())+ "/";
    	}
    	Log.d(tag,pr);
    }
}
